package com.jdzy.student.controller;

import com.jdzy.model.common.vos.Result;
import com.jdzy.model.common.vos.ResultA;
import com.jdzy.model.common.vos.ResultCodeEnum;
import com.jdzy.model.student.dtos.StudentLoginDto;
import com.jdzy.model.student.vos.CaptchaVo;
import com.jdzy.model.teacher.dtos.LoginDto;
import com.jdzy.model.teacher.vos.LoginVo;
import com.jdzy.student.service.StudentService;
import com.jdzy.student.service.SysMenuService;
import com.jdzy.student.service.SysUserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(value = "登录的controller类")
@CrossOrigin(allowCredentials = "true" , allowedHeaders = "*")
public class LoginController {

    @Autowired
    private StudentService studentService;
    @Autowired
    private SysMenuService sysMenuService;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户登录操作
     *
     * @param
     * @return
     */

    @GetMapping("login/captcha")
    public ResultA<CaptchaVo> getCaptcha() {
        return ResultA.ok(studentService.getCaptcha());
    }

    @PostMapping("api/student/studentLogin")
    public Result studentLogin(@RequestBody StudentLoginDto studentLoginDto) {
        log.info("学生登录操作,参数:{}", studentLoginDto);
        return studentService.studentLogin(studentLoginDto);
    }

    @GetMapping("api/student/info")
    public Result getStudentInfo(@RequestParam String token) {
        log.info("根据token获取学生信息,参数:{}", token);
        return studentService.getStudentInfo(token);
    }

    @PostMapping(value = "api/teacher/teacherLogin")
    public ResultA<LoginVo> teacherLogin(@RequestBody LoginDto loginDto) {
        LoginVo loginVo = sysUserService.login(loginDto);
        log.info("教师登录操作,参数:{}", loginDto);
        return ResultA.build(loginVo, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("api/teacher/info")
    public Result getTeacherInfo(@RequestHeader("token") String token) {
        log.info("根据token获取教师信息,参数:{}", token);
        return sysUserService.getTeacherInfo(token);
    }
}
